/*
 * @Description: Description
 * @Author: M
 * @LastEditors: LL
 * @Date: 2020-11-02 09:16:42
 * @LastEditTime: 2021-03-27 17:29:53
 */
import axios from 'axios'
import { Message } from 'element-ui'
// import qs from 'qs'

const NODE_ENV = process.env.NODE_ENV
const mapping = {
  development: '', // 开发
  production: '/opm/api', // 正式
  staging: '' // 宝武基座
}
document.cookie = 'JSESSIONID=7B68784A710CBBC4092D06FAF9D6E5EF'
axios.defaults.baseURL = mapping[NODE_ENV]
axios.defaults.withCredentials = true
// 拦截器
axios.interceptors.request.use(function(config) {
  config.headers['Content-Type'] = 'application/json'
  return config
}, function(error) {
  return Promise.reject(error)
})

// respone拦截器
axios.interceptors.response.use(
  response => {
    if (response.data.__sys__) {
      Message({
        message: response.data.__sys__.msg,
        type: 'error',
        duration: 2 * 1000
      })
      window.location.href = '/opm/login.jsp'
    }
    return response.data
  },
  (error) => {
    return Promise.reject(error)
  }
)

export default axios
